package javamusic.DAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;

import javamusic.excepcion.DAOExcepcion;
import javamusic.modelo.Factura;
import javamusic.util.ConexionBDKaraoke;

public class FacturaDAO extends BaseDAO {

	public Collection<Factura> buscarnumerofactura(int idcomprobante) throws DAOExcepcion {
		String query = "select numerofactura, ruc, idcomprobante from factura where idcomprobante like ?";
		Collection<Factura> lista = new ArrayList<Factura>();
		Connection con = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		try {
			con = ConexionBDKaraoke.obtenerConexion();
			stmt = con.prepareStatement(query);
			stmt.setString(1, "%" + idcomprobante + "%");
			rs = stmt.executeQuery();
			while (rs.next()) {
				Factura vo = new Factura();
				vo.setNumerofactura(rs.getString("numerofactura"));
				vo.setRuc(rs.getString("ruc"));
				vo.setIdcomprobante(rs.getInt("idcomprobante"));
				lista.add(vo);
			}
		} catch (SQLException e) {
			System.err.println(e.getMessage());
			throw new DAOExcepcion(e.getMessage());
		} finally {
			this.cerrarResultSet(rs);
			this.cerrarStatement(stmt);
			this.cerrarConexion(con);
		}
						
		return lista;
	}

	
}
